package com.meitun.mama.ui;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;

import com.meitun.mama.inject.Injector;
import com.meitun.mama.util.Config;

/**
 * Created by sunny01 on 2016/3/27.
 */
public abstract class BaseActivity extends FragmentActivity {

    public final String TAG = this.getClass().getSimpleName();

    protected abstract int getLayoutId();

    protected void initBundle(Bundle savedInstanceState) {
    }
    protected abstract void initView();

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        if (Config.isDebug) {
            Log.e(TAG, "onPostCreate:"+savedInstanceState);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Config.isDebug) {
            Log.e(TAG, "onCreate "+savedInstanceState);
        }
        if (savedInstanceState == null) {
            initBundle(getIntent().getExtras());
        } else {
            Injector.onRestore(this, savedInstanceState);
        }
        setContentView(getLayoutId());
        Injector.injectActivity(this);
        initView();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if (Config.isDebug) {
            Log.e(TAG, "onSaveInstanceState "+outState);
        }
        Injector.save(this, outState);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        if (Config.isDebug) {
            Log.e(TAG, "onRestoreInstanceState "+savedInstanceState);
        }
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        if (Config.isDebug) {
            Log.e(TAG, "onRestart ");
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (Config.isDebug) {
            Log.e(TAG, "onStart ");
        }
    }

    @Override
    protected void onPostResume() {
        super.onPostResume();
        if (Config.isDebug) {
            Log.e(TAG, "onStart ");
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (Config.isDebug) {
            Log.e(TAG, "onResume ");
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (Config.isDebug) {
            Log.e(TAG, "onPause ");
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (Config.isDebug) {
            Log.e(TAG, "onStop ");
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (Config.isDebug) {
            Log.e(TAG, "onDestroy ");
        }
    }
}
